//--------------------------------------------------- // Purpose: Remove all non-ascii characters from a file // Author: John Gauch //--------------------------------------------------- #include #include #include using namespace std; int main(int argc, char *argv[]) { // Error checking arguments if (argc != 3) { cerr << "Usage: ascii infile outfile\n"; exit(EXIT_FAILURE); } // Open input file ifstream din; din.open(argv[1]); if (din.fail()) { cerr << "Error not open input file: " << argv[1] << endl; exit(EXIT_FAILURE); } // Open output file ofstream dout; dout.open(argv[2]); if (dout.fail()) { cerr << "Error not open output file:" << argv[2] << endl; exit(EXIT_FAILURE); } // Loop reading and writing char ch; const char FIND = 13; const char REPLACE = ' '; while (din.get(ch)) { if (ch == FIND) dout << REPLACE; else if (isprint(ch) || isspace(ch)) dout << ch; } // Close files din.close(); dout.close(); }